﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using FarPoint.Win.Spread;
using FBWMS.DataBase;
using FBWMS.Properties;
using ThoughtWorks.QRCode.Codec;
using BarcodeLib;
using System.Globalization;

namespace FBWMS
{
    public partial class F_COM_Report_Task : Form
    {
        private static ds_Label.DataDataTable dt_Report = new ds_Label.DataDataTable();

        private static string str_CatronLabelFormat = "";

        ////////////////////////////////////////////////////////////////////////////
        //
        //初期処理
        //
        ////////////////////////////////////////////////////////////////////////////
        public F_COM_Report_Task()
        {
             
            try
            {
                InitializeComponent();

                //共通パス設定
                G_CommonDefine.G_CommonPath = G_CommonClassSystem.G_System_GetCommonPath();

                //XMLファイル(ini)読込                
                G_CommonClassSystem.G_System_GetCommonDefine();

                //タイマーのインターバルを設定
                this.timer1.Interval = G_CommonDefine.G_IntervalReport;

                //出力帳票名コンボボックス生成
                DataSet ds = new DataSet();
                ds.Tables.Add();

                ds.Tables[0].Columns.Add();
                ds.Tables[0].Columns.Add();

                ds.Tables[0].Rows.Add();
                ds.Tables[0].Rows.Add();
                ds.Tables[0].Rows.Add();
                ds.Tables[0].Rows.Add();
                ds.Tables[0].Rows.Add();
                ds.Tables[0].Rows.Add();

                ds.Tables[0].Rows[0][0] = "";
                ds.Tables[0].Rows[0][1] = Resources.全て;
                ds.Tables[0].Rows[1][0] = "R_SykMeisaisyo";
                ds.Tables[0].Rows[1][1] = Resources.出荷明細書;
                ds.Tables[0].Rows[2][0] = "R_NykLabel_ADJ";
                ds.Tables[0].Rows[2][1] = Resources.入庫ラヘル;
                ds.Tables[0].Rows[3][0] = "R_Nifuda_Sagawa";
                ds.Tables[0].Rows[3][1] = Resources.荷札;
                ds.Tables[0].Rows[4][0] = "R_ShohBC";
                ds.Tables[0].Rows[4][1] = Resources.商品ハーコート;
                ds.Tables[0].Rows[5][0] = "None";
                ds.Tables[0].Rows[5][1] = Resources.未出力;

                G_CommonClassControl.G_Control_SetData_ComboBox(this.cmb_Print_NM, ds, 1, 0);

                //日付の設定
                this.txt_ST_DT.Text = DateTime.Now.ToString("yyyy/MM/dd");
                this.txt_ED_DT.Text = DateTime.Now.ToString("yyyy/MM/dd");

                //サブフォームの交互色の設定
                //this.mr_F_COM_Report_Task_SUB.AlternateMRowColor = true;
                //this.mr_F_COM_Report_Task_SUB.MRowColorPattern = G_CommonDefine.G_col_MultiRowSheetBackColor;

                //ToolTipの設定
                G_CommonDefine.G_tt_ToolTip.RemoveAll();
                G_CommonDefine.G_tt_ToolTip.SetToolTip(this.btn_Search, "F1");

                //サブフォームデータ取得
                this.uSP_PC_F_COM_Report_Task_SUB_DataSelectTableAdapter.Fill(this.ds_F_COM_Report_Task.USP_PC_F_COM_Report_Task_SUB_DataSelect, this.cmb_Print_NM.SelectedValue.ToString(), this.txt_Work_CD.Text, this.txt_ST_DT.Text, this.txt_ED_DT.Text);

                int int_Count = this.ds_F_COM_Report_Task.USP_PC_F_COM_Report_Task_SUB_DataSelect.Rows.Count;

                if (0 < int_Count && this.ds_F_COM_Report_Task.USP_PC_F_COM_Report_Task_SUB_DataSelect.Rows[0]["Fin_FG"].ToString() == "False")
                {
                    this.txt_Message.Text = Resources.Check;
                }
                //str_CatronLabelFormat
                //入库标签使用那种格式
                //if (G_CommonDefine.G_str_Customer_CD == "FESH")
                //{
                DataTable dt_Define = G_CommonClassBussniss.G_M_Define_HD_GetData();

                if ((dt_Define != null) && (dt_Define.Select("Item_CD='06' AND Item_Value='FESH'").Length > 0))
                {
                    str_CatronLabelFormat = "FESH";
                }
                //}
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, Resources.エラー, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        #region イベントハンドラ ***********************************************************

        ////////////////////////////////////////////////////////////////////////////
        //
        //検索ボタンクリック時処理
        //
        ////////////////////////////////////////////////////////////////////////////
        private void btn_Search_Click(object sender, EventArgs e)
        {
            try
            {
                //待機画面の表示
                G_CommonClassOther.G_Other_WaitForm(true);

                //検索処理
                this.P_Search();
                //G_PrintShipCase("2");
            }
            catch (Exception err)
            {
                //エラーメッセージ表示
                MessageBox.Show(Resources.BtnSearchClick処理エラー + err.Message, Resources.エラー, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                if (G_CommonDefine.G_F_COM_Waiting != null)
                {
                    //待機画面の解除
                    G_CommonClassOther.G_Other_WaitForm(false);
                }
            }
        }

        ////////////////////////////////////////////////////////////////////////////
        //
        //サブフォームセルクリック時処理
        //
        ////////////////////////////////////////////////////////////////////////////
        //private void mr_F_COM_Report_Task_SUB_CellClick(object sender, GrapeCity.Win.ElTabelle.MClickEventArgs e)
        //{
        //    try
        //    {
        //        if (e.Position.Column.Equals(0))
        //        {
        //            if (DialogResult.Cancel == MessageBox.Show("再発行します。よろしいですか？", "確認", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
        //            {
        //                return;
        //            }

        //            //サブフォームセルクリック処理
        //            this.P_Sub_CellClick();
        //        }
        //    }
        //    catch (Exception err)
        //    {
        //        MessageBox.Show("mr_F_COM_Report_Task_SUB_CellClick処理エラー" + err.Message, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
        //    }
        //}

        /// <summary>
        /// 未出力帳票再発行フラグ
        /// </summary>
        private bool isReprint = false;
                
        ////////////////////////////////////////////////////////////////////////////
        //
        //タイマー処理
        //
        ////////////////////////////////////////////////////////////////////////////
        private void timer1_Tick(object sender, EventArgs e)
        {
            SqlConnection connect = null;

            DataSet ds;

            try
            {
                //現在時刻表示
                this.txt_NowTime.Text = DateTime.Now.ToString("yyyy/MM/dd HH:mm");

                //USP_ADP_F_COM_Print_Task_DataSelectを実行してレコードセットを返す方法
                
                connect = new SqlConnection();

                if (!G_CommonClassDB.G_DB_Connect(out connect))
                {
                    MessageBox.Show(Resources.DB连接错误, Resources.DB连接错误);
                    return;
                }

                //ストアド実行(帳票出力レコード取得)
                switch (G_CommonClassDB.G_DB_ExecStoredProc(connect, out ds, "USP_PC_F_COM_Report_Task_DataSelect"))
                {
                    case G_CommonDefine.RetValue.FoldarNotExistsError:
                        break;
                    case G_CommonDefine.RetValue.FileNotExistsError:
                        break;
                    case G_CommonDefine.RetValue.UndefinedError:
                        break;
                    case G_CommonDefine.RetValue.NoData:
                        break;
                    case G_CommonDefine.RetValue.GetData:

                        //出力Que分ループする
                        //SqlConnection connect_WK = null;
                        //SqlCommand sqlCmd = null;
                        //SqlParameter[] sqlPara = new SqlParameter[1];
                        timer1.Stop();
                        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                        {
                            //QueID表示
                            this.txt_Que_ID.Text = ds.Tables[0].Rows[i]["Que_ID"].ToString();
                            //帳票名称表示
                            this.txt_Print_NM.Text = ds.Tables[0].Rows[i]["Print_NM"].ToString();
                            //プリンタ名称表示
                            this.txt_Printer_NM.Text = ds.Tables[0].Rows[i]["Printer_NM"].ToString();
                            //PC名称表示
                            this.txt_PC_NM.Text = ds.Tables[0].Rows[i]["PC_NM"].ToString();                            

                            // レポートを生成してビューワコントロールに表示します。
                            Assembly asm = Assembly.GetExecutingAssembly();
                            Type t;
                            Object obj;
                            
                            ReportDocument rpt;

                            if (dt_Report != null)
                            {
                                dt_Report.Clear();
                            }

                            //t = asm.GetType(asm.GetName().Name + "." + ds.Tables[0].Rows[i]["Print_NM"].ToString());
                            if ((ds.Tables[0].Rows[i]["Print_NM"].ToString() == "R_HOEI_Carton") && (str_CatronLabelFormat == "FESH"))
                            {
                                t = asm.GetType("FBWMS.Report." + "cy_NOSerial");
                            }
                            else
                            {
                                t = asm.GetType("FBWMS.Report." + ds.Tables[0].Rows[i]["Print_NM"].ToString());
                            }

                            obj = t.InvokeMember(null, BindingFlags.CreateInstance, null, null, null);
                            rpt = (ReportDocument)(obj);

                            //レポートとのDB接続
                            //DB接続文字列生成d
                            //string stConnectionString = string.Empty;
                            //stConnectionString += "Data Source = " + G_CommonDefine.G_DBServer + ";";
                            //stConnectionString += "Initial Catalog = " + G_CommonDefine.G_DBCatalog + ";";
                            //stConnectionString += "Integrated Security = " + G_CommonDefine.G_DBSecurity + ";";
                            //stConnectionString += "User ID = " + G_CommonDefine.G_DBUser + ";";
                            //stConnectionString += "Password = " + G_CommonDefine.G_DBPass + ";";

                            //SQL文生成
                            //DataDynamics.ActiveReports.DataSources.SqlDBDataSource myDS = new DataDynamics.ActiveReports.DataSources.SqlDBDataSource();
                            
                            //myDS.ConnectionString = stConnectionString;

                            DataSet ds_R_ShohBC = new DataSet();

                            //帳票によって設定するストアドを変更する。
                            DataTable dt_Search = null;
                            string Que_ID = "0";
                            switch (ds.Tables[0].Rows[i]["Print_NM"].ToString())
                            {
                                case "R_ShipmentCase":
                                    if (G_PrintShipCase(ds.Tables[0].Rows[i]["Que_ID"].ToString()))
                                    {
                                        rpt.SetDataSource((DataTable)dt_Report);

                                        //cy.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)int_Paper;
                                        BlobFieldObject imageObject =
                                            (BlobFieldObject)rpt.ReportDefinition.ReportObjects["BarCode1"] as BlobFieldObject;
                                        imageObject.Width = 91 * 15; //报表中的长宽单位是缇，1像素=15缇
                                        imageObject.Height = 91 * 15;

                                    }
                                    break;
                                case "R_HOEI_Carton":

                                    if (str_CatronLabelFormat == "FESH")
                                    {
                                        if (G_HOEI_Carton_SH(ds.Tables[0].Rows[i]["Que_ID"].ToString()))
                                        {
                                            dt_Report.DefaultView.Sort = "CaseNo";
                                            rpt.SetDataSource((DataTable)dt_Report);
                                            ////rpt.
                                            ////cy.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)int_Paper;
                                            BlobFieldObject imageObject =
                                                (BlobFieldObject)rpt.ReportDefinition.ReportObjects["BarCode1"] as BlobFieldObject;
                                            imageObject.Width = 110 * 15; //报表中的长宽单位是缇，1像素=15缇
                                            imageObject.Height = 110 * 15;
                                        }
                                    }
                                    else
                                    {
                                        if (G_HOEI_Carton(ds.Tables[0].Rows[i]["Que_ID"].ToString()))
                                        {
                                            dt_Report.DefaultView.Sort = "CaseNo";
                                            rpt.SetDataSource((DataTable)dt_Report);
                                            //rpt.
                                            //cy.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)int_Paper;
                                            BlobFieldObject imageObject =
                                                (BlobFieldObject)rpt.ReportDefinition.ReportObjects["BarCode1"] as BlobFieldObject;
                                            imageObject.Width = 91 * 15; //报表中的长宽单位是缇，1像素=15缇
                                            imageObject.Height = 91 * 15;

                                        }
                                    }


                                    break;
                                    //Add by Michael A4 Serial
                                case "R_SerialList":

                                    Que_ID = ds.Tables[0].Rows[i]["Que_ID"].ToString();

                                    dt_Search = G_CommonClassBussniss.G_A4SerialPrint_SearchData(Que_ID);

                                    if ((dt_Search != null) && (dt_Search.Rows.Count > 0))
                                    {
                                        string str_FB_NO = dt_Search.Rows[0]["FB_NO"].ToString();
                                        string str_FBPOS_NO = dt_Search.Rows[0]["FBPOS_NO"].ToString();
                                        string str_SEQ_NO = dt_Search.Rows[0]["SEQ_NO"].ToString();
                                        string str_Work_CD = dt_Search.Rows[0]["Work_CD"].ToString();

                                        DataSet ds_Report = G_PrintSerialList(str_FB_NO, str_FBPOS_NO, str_SEQ_NO, str_Work_CD);

                                        rpt.SetDataSource(ds_Report);    
                                    }
                                    break;
                                case "R_SigleSerial":
                                    Que_ID = ds.Tables[0].Rows[i]["Que_ID"].ToString();

                                    dt_Search = G_CommonClassBussniss.G_A4SerialPrint_SearchData(Que_ID);

                                    if ((dt_Search != null) && (dt_Search.Rows.Count > 0))
                                    {

                                        string str_Shoh_CD = dt_Search.Rows[0]["Shoh_CD"].ToString();
                                        string str_SerialNo = dt_Search.Rows[0]["Shoh_NM"].ToString();

                                        if (str_Shoh_CD.ToString() != string.Empty)
                                        {
                                            //Single Serial Label
                                            DataTable dt = G_PrintSerialSingle(str_Shoh_CD, str_SerialNo);
                                            rpt.SetDataSource((DataTable)dt);
                                            BlobFieldObject imageObject =
                                              (BlobFieldObject)rpt.ReportDefinition.ReportObjects["BarCode1"] as BlobFieldObject;
                                            imageObject.Width = 91 * 15; //报表中的长宽单位是缇，1像素=15缇
                                            imageObject.Height = 91 * 15;
                                        }
                                        else
                                        {
                                            //Multiple Serial Label
                                            string str_FB_NO = dt_Search.Rows[0]["FB_NO"].ToString();
                                            string str_FBPOS_NO = dt_Search.Rows[0]["FBPOS_NO"].ToString();
                                            string str_SEQ_NO = dt_Search.Rows[0]["SEQ_NO"].ToString();

                                            DataTable dt_SerialList = G_CommonClassBussniss.G_A4SerialPrint_GetDetailData(str_FB_NO, str_FBPOS_NO, str_SEQ_NO);

                                            DataTable dt = G_PrintSerialMultiple(dt_SerialList);
                                            rpt.SetDataSource((DataTable)dt);
                                            BlobFieldObject imageObject =
                                              (BlobFieldObject)rpt.ReportDefinition.ReportObjects["BarCode1"] as BlobFieldObject;
                                            imageObject.Width = 91 * 15; //报表中的长宽单位是缇，1像素=15缇
                                            imageObject.Height = 91 * 15;
                                        }

                                    }
                                    break;
                                case "R_LotLabel":
                                    Que_ID = ds.Tables[0].Rows[i]["Que_ID"].ToString();
                                    DataTable dt_Data = P_NewLotLabelDataSearch(Que_ID);

                                    if ((dt_Data != null) && (dt_Data.Rows.Count > 0))
                                    {
                                        string str_FB_NO = dt_Data.Rows[0]["FB_NO"].ToString();
                                        string str_FBPOS_NO = dt_Data.Rows[0]["FBPOS_NO"].ToString();
                                        string str_SEQ_NO = dt_Data.Rows[0]["SEQ_NO"].ToString();
                                        if (str_FB_NO.Length == 0)
                                        {
                                            ds_LotLabel ds_Label = G_PrintLotLabel(dt_Data);

                                            rpt.SetDataSource((DataSet)ds_Label);
                                        }
                                        else
                                        {
                                            DataTable dt_Lotdata = G_CommonClassBussniss.G_LotLabelList_GetData(str_FB_NO, str_FBPOS_NO, str_SEQ_NO);

                                            if ((dt_Lotdata != null) && (dt_Lotdata.Rows.Count > 0))
                                            {
                                                ds_LotLabel ds_Label = G_PrintLotLabelList(dt_Lotdata);

                                                rpt.SetDataSource((DataSet)ds_Label);
                                            }
                                        }

                                    }


                                    break;
                                case "R_LotLabel_New":
                                    Que_ID = ds.Tables[0].Rows[i]["Que_ID"].ToString();
                                    DataTable dt_Data2 = P_NewLotLabelDataSearch(Que_ID);

                                    if ((dt_Data2 != null) && (dt_Data2.Rows.Count > 0))
                                    {
                                        string str_FB_NO = dt_Data2.Rows[0]["FB_NO"].ToString();
                                        string str_FBPOS_NO = dt_Data2.Rows[0]["FBPOS_NO"].ToString();
                                        string str_SEQ_NO = dt_Data2.Rows[0]["SEQ_NO"].ToString();
                                        if (str_FB_NO.Length == 0)
                                        {
                                            ds_LotLabel ds_Label = G_PrintLotLabel(dt_Data2);

                                            rpt.SetDataSource((DataSet)ds_Label);
                                        }
                                        else
                                        {
                                            DataTable dt_Lotdata = G_CommonClassBussniss.G_LotLabelList_GetData(str_FB_NO, str_FBPOS_NO, str_SEQ_NO);

                                            if ((dt_Lotdata != null) && (dt_Lotdata.Rows.Count > 0))
                                            {
                                                ds_LotLabel ds_Label = G_PrintLotLabelList(dt_Lotdata);

                                                rpt.SetDataSource((DataSet)ds_Label);
                                            }
                                        }

                                    }


                                    break;
                                /*case "R_NykLabel_ADJ":
                                    myDS.SQL = "EXEC USP_PC_R_NykLabel_DataSelect " + ds.Tables[0].Rows[i]["Que_ID"].ToString();
                                    break;
                                case "R_NykLabel":
                                    myDS.SQL = "EXEC USP_PC_R_NykLabel_DataSelect " + ds.Tables[0].Rows[i]["Que_ID"].ToString();
                                    break;
                                case "R_Nifuda":
                                    myDS.SQL = "EXEC USP_PC_R_Nifuda_DataSelect " + ds.Tables[0].Rows[i]["Que_ID"].ToString();
                                    break;
                                case "R_Nifuda_Sagawa":
                                    myDS.SQL = "EXEC USP_PC_R_Nifuda_DataSelect " + ds.Tables[0].Rows[i]["Que_ID"].ToString();
                                    break;
                                case "R_Nouhinsyo":
                                    myDS.SQL = "EXEC USP_PC_R_Nouhinsyo_DataSelect " + ds.Tables[0].Rows[i]["Que_ID"].ToString();
                                    break;
                                case "R_ShohBC":
                                    myDS.SQL = "EXEC USP_PC_R_ShohBC_DataSelect " + ds.Tables[0].Rows[i]["Que_ID"].ToString();
                                    //印刷枚数取得
                                    ds_R_ShohBC = this.P_Get_R_ShohBC_QT(ds.Tables[0].Rows[i]["Que_ID"].ToString());
                                    break;*/
                            }
                            
                            //rpt.DataSource = myDS;

                            //出力プリンタ出力
                            rpt.PrintOptions.PrinterName = ds.Tables[0].Rows[i]["Printer_NM"].ToString();
                            //rpt.Document.Printer.PrinterSettings.PrinterName = ds.Tables[0].Rows[i]["Printer_NM"].ToString();

                            //商品バーコードのときのみ印刷枚数指定
                            if (ds.Tables[0].Rows[i]["Print_NM"].ToString() == "R_ShohBC")
                            {
                                //出力枚数設定
                                //rpt.Document.Printer.PrinterSettings.Copies = short.Parse(ds_R_ShohBC.Tables[0].Rows[0]["Inji_QT"].ToString());
                                //rpt.PrintOptions.c
                                rpt.PrintToPrinter(short.Parse(ds_R_ShohBC.Tables[0].Rows[0]["Inji_QT"].ToString()), true, 0, 0);
                            }
                            else
                            {
                                //出力枚数設定
                                //rpt.Document.Printer.PrinterSettings.Copies = 1;
                                rpt.PrintToPrinter(1, true, 0, 0);
                            }

                            //rpt.Run(false);
                            //プリンタ出力
                            //rpt.Document.Print(false, false, false);
                            
                            //FIn_FGをONにする。
                            SqlConnection connect_WK = null;
                            if (!G_CommonClassDB.G_DB_Connect(out connect_WK))
                            {
                                MessageBox.Show(Resources.P_Search, Resources.DB接続エラー);
                                return;
                            }

                            SqlCommand sqlCmd = null;
                            sqlCmd = connect_WK.CreateCommand();

                            SqlParameter[] sqlOutPara;
                            SqlParameter[] sqlPara = new SqlParameter[3];

                            sqlPara[0] = G_CommonClassDB.G_DB_SetSQLDBParameter("@Que_ID", ParameterDirection.Input, SqlDbType.Int, 1, ds.Tables[0].Rows[i]["Que_ID"].ToString());
                            sqlPara[1] = G_CommonClassDB.G_DB_SetSQLDBParameter("@Fin_FG", ParameterDirection.Input, SqlDbType.Int, 1, "1");
                            sqlPara[2] = G_CommonClassDB.G_DB_SetSQLDBParameter("@Ret", ParameterDirection.Output, SqlDbType.Int, 1, "0");

                            switch (G_CommonClassDB.G_DB_ExecStoredProc(connect_WK, sqlCmd, "USP_PC_F_COM_Report_Task_DataUpdate", sqlPara, out sqlOutPara))
                            {
                                case G_CommonDefine.RetValue.FoldarNotExistsError:
                                    break;
                            }

                            //返り値判定
                            if (sqlOutPara[0].Value.ToString() != "0")
                            {
                                return;
                            }

                            connect_WK = null;

                            if (isReprint)
                            {
                                this.cmb_Print_NM.SelectedIndex = 0;
                                this.txt_Work_CD.Text = string.Empty;
                                this.txt_ST_DT.Text = DateTime.Now.ToString("yyyy/MM/dd");
                                this.txt_ED_DT.Text = DateTime.Now.ToString("yyyy/MM/dd");

                                //サブフォームデータ取得
                                this.uSP_PC_F_COM_Report_Task_SUB_DataSelectTableAdapter.Fill(this.ds_F_COM_Report_Task.USP_PC_F_COM_Report_Task_SUB_DataSelect, this.cmb_Print_NM.SelectedValue.ToString(), this.txt_Work_CD.Text, this.txt_ST_DT.Text, this.txt_ED_DT.Text);

                                int int_Count = this.ds_F_COM_Report_Task.USP_PC_F_COM_Report_Task_SUB_DataSelect.Rows.Count;

                                if (0 < int_Count && this.ds_F_COM_Report_Task.USP_PC_F_COM_Report_Task_SUB_DataSelect.Rows[0]["Fin_FG"].ToString() == "False")
                                {
                                    this.txt_Message.Text = Resources.Check;
                                }
                                else
                                {
                                    this.txt_Message.Text = string.Empty;
                                }

                                isReprint = false;
                            }
                        }                        

                        break;
                }
                timer1.Start();
                Application.DoEvents();
                //System.GC.Collect();
            }
            catch (Exception err)
            {
                //ログ書込み
                G_CommonClassSystem.G_System_SetLog(G_CommonDefine.LogMode.Error, Resources.印刷処理エラー + err.Message, "帳票タスク");

                string str_Que_ID = this.txt_Que_ID.Text;

                //プリンター名称書き換え処理
                this.P_Printer_NM_DataUpdate(connect, str_Que_ID, "");
                
                this.cmb_Print_NM.SelectedIndex = 0;
                this.txt_Work_CD.Text = string.Empty;
                this.txt_ST_DT.Text = DateTime.Now.ToString("yyyy/MM/dd");
                this.txt_ED_DT.Text = DateTime.Now.ToString("yyyy/MM/dd");

                //サブフォームデータ取得
                this.uSP_PC_F_COM_Report_Task_SUB_DataSelectTableAdapter.Fill(this.ds_F_COM_Report_Task.USP_PC_F_COM_Report_Task_SUB_DataSelect, this.cmb_Print_NM.SelectedValue.ToString(), this.txt_Work_CD.Text, this.txt_ST_DT.Text, this.txt_ED_DT.Text);

                this.txt_Message.Text = Resources.Check;
                timer1.Start();
            }
            finally
            {
                //DB開放
                timer1.Start();
                if (!G_CommonClassDB.G_DB_Dispose(connect))
                {
                    MessageBox.Show(Resources.UpdateData, Resources.DB接続解放エラー);                    
                }
            }
        }



        ////////////////////////////////////////////////////////////////////////////
        //
        //開始日付ボタンクリック時処理
        //
        ////////////////////////////////////////////////////////////////////////////
        private void btn_ST_DT_Click(object sender, EventArgs e)
        {
            try
            {
                G_CommonDefine.G_Target_Date = this.txt_ST_DT.Text;

                Form F_COM_Calender = new F_COM_Calender();
                F_COM_Calender.ShowDialog();

                this.txt_ST_DT.Text = G_CommonDefine.G_Target_Date;
            }
            catch (Exception err)
            {
                //エラーメッセージ表示
                MessageBox.Show(Resources.Btn_ST_DT_Click + err.Message, Resources.エラー, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        ////////////////////////////////////////////////////////////////////////////
        //
        //終了日付ボタンクリック時処理
        //
        ////////////////////////////////////////////////////////////////////////////
        private void btn_ED_DT_Click(object sender, EventArgs e)
        {
            try
            {
                G_CommonDefine.G_Target_Date = this.txt_ED_DT.Text;

                Form F_COM_Calender = new F_COM_Calender();
                F_COM_Calender.ShowDialog();

                this.txt_ED_DT.Text = G_CommonDefine.G_Target_Date;
            }
            catch (Exception err)
            {
                //エラーメッセージ表示
                MessageBox.Show(Resources.Btn_ED_DT_Click + err.Message, Resources.エラー, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        ////////////////////////////////////////////////////////////////////////////
        //
        //ログインボタンクリック時処理
        //
        ////////////////////////////////////////////////////////////////////////////
        private void btn_LogIn_Click(object sender, EventArgs e)
        {
            //ログイン画面を開く
            G_CommonClassOther.G_Other_FormOpen(0, Resources.FLogIn);
        }

        ////////////////////////////////////////////////////////////////////////////
        //
        //サブフォームセルダブルクリック時処理
        //
        ////////////////////////////////////////////////////////////////////////////
        //private void mr_F_COM_Report_Task_SUB_CellDoubleClick(object sender, GrapeCity.Win.ElTabelle.MClickEventArgs e)
        //{
        //    int int_Current = this.mr_F_COM_Report_Task_SUB.ActiveSheet.ActiveRowIndex + 1;
        //    int int_Total = this.mr_F_COM_Report_Task_SUB.ActiveSheet.Rows.Count;

        //    MessageBox.Show(string.Format("現在のレコード : {0} / レコード総数 : {1}", int_Current, int_Total));
        //}

        #endregion *************************************************************************

        #region プライベート関数 ***********************************************************

        /// <summary>
        /// 検索処理
        /// </summary>
        private void P_Search()
        {
            //サブフォームデータ取得
            this.uSP_PC_F_COM_Report_Task_SUB_DataSelectTableAdapter.Fill(this.ds_F_COM_Report_Task.USP_PC_F_COM_Report_Task_SUB_DataSelect, this.cmb_Print_NM.SelectedValue.ToString(), this.txt_Work_CD.Text, this.txt_ST_DT.Text, this.txt_ED_DT.Text);
            P_BindGrid(this.mr_F_COM_Report_Task_SUB_Sheet1, this.ds_F_COM_Report_Task.USP_PC_F_COM_Report_Task_SUB_DataSelect);
        }

        /// <summary>
        /// プリンタ名称書き換え処理
        /// </summary>
        private void P_Printer_NM_DataUpdate(SqlConnection connect, string str_Que_ID, string str_Printer_NM)
        {
            try
            {
                SqlCommand sqlCmd = connect.CreateCommand();

                SqlParameter[] sqlOutPara;
                SqlParameter[] sqlPara = new SqlParameter[3];

                sqlPara[0] = G_CommonClassDB.G_DB_SetSQLDBParameter("@Que_ID", ParameterDirection.Input, SqlDbType.Int, 0, str_Que_ID);
                sqlPara[1] = G_CommonClassDB.G_DB_SetSQLDBParameter("@Printer_NM", ParameterDirection.Input, SqlDbType.VarChar, 0, str_Printer_NM);
                sqlPara[2] = G_CommonClassDB.G_DB_SetSQLDBParameter("@Ret", ParameterDirection.Output, SqlDbType.Int, 0, Resources.msg_0);

                G_CommonClassDB.G_DB_ExecStoredProc(connect, sqlCmd, "USP_PC_F_COM_Report_Task_Printer_NM_DataUpdate", sqlPara, out sqlOutPara);
            }
            catch (Exception err)
            {
                //ログ書込み
                G_CommonClassSystem.G_System_SetLog(G_CommonDefine.LogMode.Error, Resources.印刷中止処理エラー + err.Message, "帳票タスク");
            }
        }
        private void fpSpread1_ButtonClicked(object sender, EditorNotifyEventArgs e)
        {
            try
            {
                P_Sub_CellClick();
            }
            catch (Exception err)
            {
                string str_Caption = G_CommonClassSystem.G_System_GetMessage(G_CommonDefine.G_Message_Error);
                G_CommonClassSystem.G_System_SetLog(G_CommonDefine.LogMode.Error, Resources.ButtonClicked + err.Message, "ButtonClicked");
                MessageBox.Show(err.Message, str_Caption, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }
        /// <summary>
        /// サブフォームセルクリック処理
        /// </summary>
        private void P_Sub_CellClick()
        {
            SqlConnection connect = null;

            try
            {
                if (!G_CommonClassDB.G_DB_Connect(out connect))
                {
                    MessageBox.Show(Resources.P_Search, Resources.DB接続エラー);
                    return;
                }

                int int_Row = this.mr_F_COM_Report_Task_SUB.ActiveSheet.ActiveRowIndex;

                if ((this.ds_F_COM_Report_Task.USP_PC_F_COM_Report_Task_SUB_DataSelect.Rows[int_Row]["Fin_FG"].ToString() == "False") || (this.ds_F_COM_Report_Task.USP_PC_F_COM_Report_Task_SUB_DataSelect.Rows[int_Row]["Printer_NM"].ToString().Trim() == string.Empty))
                {
                    Form F_COM_Report_Task_PopUp = new F_COM_Report_Task_PopUp();

                    F_COM_Report_Task_PopUp.ShowDialog();

                    if (G_CommonDefine.G_Report_Printer_NM.Equals(string.Empty))
                    {
                        return;
                    }

                    string str_Que_ID = this.ds_F_COM_Report_Task.USP_PC_F_COM_Report_Task_SUB_DataSelect.Rows[int_Row]["Que_ID"].ToString();

                    string str_Printer_NM = G_CommonDefine.G_Report_Printer_NM;

                    //プリンタ名称書き換え処理
                    this.P_Printer_NM_DataUpdate(connect, str_Que_ID, str_Printer_NM);

                    isReprint = true;
                }
                else
                {
                    SqlCommand sqlCmd = connect.CreateCommand();
                    SqlParameter[] sqlPara = new SqlParameter[3];
                    SqlParameter[] sqlOutPara;

                    //FIn_FGをONにする。
                    sqlPara[0] = G_CommonClassDB.G_DB_SetSQLDBParameter("@Que_ID", ParameterDirection.Input, SqlDbType.Int, 1, this.ds_F_COM_Report_Task.USP_PC_F_COM_Report_Task_SUB_DataSelect.Rows[int_Row]["Que_ID"].ToString());
                    sqlPara[1] = G_CommonClassDB.G_DB_SetSQLDBParameter("@Fin_FG", ParameterDirection.Input, SqlDbType.Int, 1, "0");
                    sqlPara[2] = G_CommonClassDB.G_DB_SetSQLDBParameter("@Ret", ParameterDirection.Output, SqlDbType.Int, 1, "0");

                    switch (G_CommonClassDB.G_DB_ExecStoredProc(connect, sqlCmd, "USP_PC_F_COM_Report_Task_DataUpdate", sqlPara, out sqlOutPara))
                    {
                        case G_CommonDefine.RetValue.FoldarNotExistsError:
                            break;
                    }
                }
            }
            finally
            {
                if (connect != null)
                {
                    //DB開放
                    if (!G_CommonClassDB.G_DB_Dispose(connect))
                    {
                        MessageBox.Show(Resources.UpdateData, Resources.DB接続解放エラー);
                    }
                }
            }
        }

        /// <summary>
        /// 商品バーコード出力枚数取得処理
        /// </summary>
        private DataSet P_Get_R_ShohBC_QT(string str_Que_ID)
        {
            SqlConnection connect = null;

            try
            {
                if (!G_CommonClassDB.G_DB_Connect(out connect))
                {
                    MessageBox.Show(Resources.P_Search, Resources.DB接続エラー);
                    return null;
                }

                SqlCommand sqlCmd = connect.CreateCommand();
                SqlParameter[] sqlPara = new SqlParameter[1];
                DataSet ds;

                sqlPara[0] = G_CommonClassDB.G_DB_SetSQLDBParameter("@PrintQue_No", ParameterDirection.Input, SqlDbType.Int, 0, str_Que_ID);

                G_CommonClassDB.G_DB_ExecStoredProc(connect, sqlCmd, "USP_PC_R_ShohBC_DataSelect", sqlPara, out ds);

                return ds;
            }
            finally
            {
                if (connect != null)
                {
                    //DB開放
                    if (!G_CommonClassDB.G_DB_Dispose(connect))
                    {
                        MessageBox.Show(Resources.UpdateData, Resources.DB接続解放エラー);
                    }
                }
            }
        }

        #endregion *************************************************************************
        
        #region フォーム共通処理 ***********************************************************

        ////////////////////////////////////////////////////////////////////////////
        //
        //ショートカットキー処理
        //
        ////////////////////////////////////////////////////////////////////////////
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (this.cc_ShortcutKeyHelper1.PerformClickByKeys(keyData))
            {
                return true;
            }

            return base.ProcessCmdKey(ref msg, keyData);
        }

        ////////////////////////////////////////////////////////////////////////////
        //フォームKeyDown時処理
        //(エンターを押した際に次のコントロールに移動する。)
        //(フォームの『KeyPreview』を『true』にすること)
        ////////////////////////////////////////////////////////////////////////////
        private void F_COM_Report_Task_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (!e.Control)
                {
                    this.SelectNextControl(this.ActiveControl, !e.Shift, true, true, true);
                }
            }
        }   

        #endregion *************************************************************************        

        private bool G_HOEI_Carton(string strQue_ID)
        {
            DotNetBarcode bc = new DotNetBarcode(DotNetBarcode.Types.QRCode);
            BarcodeLib.Barcode BCCODE = new Barcode(); //一维条码
            Image image;

            string str_Binary = "";
            DateTime dt_Date = DateTime.Now;
            string str_Date = "";
            SqlConnection connect_CS = null;
            SqlCommand sqlCmd_CS = null;
            if (!G_CommonClassDB.G_DB_Connect(out connect_CS))
            {
                MessageBox.Show(Resources.P_Search, Resources.DB接続エラー);
                return false;
            }
            DataSet ds_R_HOEI_Carton = new DataSet();

            sqlCmd_CS = connect_CS.CreateCommand();
            SqlParameter[] sqlPara_CS = new SqlParameter[1];
            sqlPara_CS[0] = G_CommonClassDB.G_DB_SetSQLDBParameter("@PrintQue_No", ParameterDirection.Input, SqlDbType.Int, 1, strQue_ID);

            switch (G_CommonClassDB.G_DB_ExecStoredProc(connect_CS, sqlCmd_CS, "USP_PC_F_R_HOEI_Carton_DataSelect", sqlPara_CS, out ds_R_HOEI_Carton))
            {
                case G_CommonDefine.RetValue.FoldarNotExistsError:
                    break;
                case G_CommonDefine.RetValue.FileNotExistsError:
                    break;
                case G_CommonDefine.RetValue.UndefinedError:
                    break;
                case G_CommonDefine.RetValue.NoData:
                    break;
                case G_CommonDefine.RetValue.GetData:
                    int int_Paper = -1;
                    dt_Report = new ds_Label.DataDataTable();
                    for (int j = 0; j < ds_R_HOEI_Carton.Tables[0].Rows.Count; j++)
                    {
                        //string str_Data = ds_R_HOEI_Carton.Tables[0].Rows[j]["Troi_CD"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["Shoh_CD"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["Condition"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["REF"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["Date"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["Work_CD"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["Qty"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["Label"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["Lot_No"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["FB_NO"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["FBPOS_NO"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["int_StartSeq"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["Location"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["MaxSeq"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["StrCondition"].ToString() + "<#$>";

                        if (DateTime.TryParse(ds_R_HOEI_Carton.Tables[0].Rows[j]["NYUK_DT"].ToString(), out dt_Date))
                        {
                            str_Date = dt_Date.Year.ToString("D4") + dt_Date.Month.ToString("D2") + dt_Date.Day.ToString("D2");
                        }

                        ds_Label.DataRow dr_lb = dt_Report.NewDataRow();
                        dr_lb.Tori_CD = ds_R_HOEI_Carton.Tables[0].Rows[j]["Tori_CD"].ToString();
                        dr_lb.Shoh_CD = ds_R_HOEI_Carton.Tables[0].Rows[j]["Shoh_CD"].ToString() + "\r\n" + 
                            ds_R_HOEI_Carton.Tables[0].Rows[j]["Shoh_NM"].ToString();
                        dr_lb.Souk_NM = ds_R_HOEI_Carton.Tables[0].Rows[j]["SOUK_CD"].ToString();

                        dr_lb.Jyot_KB = ds_R_HOEI_Carton.Tables[0].Rows[j]["JYOT_NM"].ToString();
                        dr_lb.Ref = ds_R_HOEI_Carton.Tables[0].Rows[j]["Lot_CD"].ToString();
                        dr_lb.NOUK_DT = ds_R_HOEI_Carton.Tables[0].Rows[j]["NYUK_DT"].ToString();
                        dr_lb.Work_CD = ds_R_HOEI_Carton.Tables[0].Rows[j]["WORK_CD"].ToString();

                        dr_lb.Lot_No = ds_R_HOEI_Carton.Tables[0].Rows[j]["SUPPLIER_NM"].ToString();
                        dr_lb.Qty = ds_R_HOEI_Carton.Tables[0].Rows[j]["ALL_QT"].ToString();
                        dr_lb.CaseNo = "Location" + ds_R_HOEI_Carton.Tables[0].Rows[j]["B_Loca_CD"].ToString();
                        //if (Info.Length > 15)
                        //{
                        //    dr_lb.IssuingDate = "重";
                        //}

                        str_Binary = "N" + SetLenth(ds_R_HOEI_Carton.Tables[0].Rows[j]["FB_NO"].ToString(), 20) + 
                            SetLenth(ds_R_HOEI_Carton.Tables[0].Rows[j]["FBPOS_NO"].ToString(), 5) + 
                            SetLenth(ds_R_HOEI_Carton.Tables[0].Rows[j]["SEQ_NO"].ToString(), 5) + 
                            SetLenth(ds_R_HOEI_Carton.Tables[0].Rows[j]["Tori_CD"].ToString(), 15) + 
                            SetLenth(ds_R_HOEI_Carton.Tables[0].Rows[j]["Shoh_CD"].ToString(), 80) + 
                            SetLenth(ds_R_HOEI_Carton.Tables[0].Rows[j]["Lot_CD"].ToString(), 50) + 
                            SetLenth("10", 2) + 
                            SetLenth(ds_R_HOEI_Carton.Tables[0].Rows[j]["ALL_QT"].ToString(), 5) + 
                            SetLenth(str_Date, 8);
                        bc.Save(str_Binary, Application.StartupPath + @"\Temp.bmp", 200, 200);
                        dr_lb.BarCode = File.ReadAllBytes(Application.StartupPath + @"\Temp.bmp");
                        dr_lb.Invoice = ds_R_HOEI_Carton.Tables[0].Rows[j]["FB_NO"].ToString() + @"/" +
                            ds_R_HOEI_Carton.Tables[0].Rows[j]["FBPOS_NO"].ToString() + @"/" + 
                            ds_R_HOEI_Carton.Tables[0].Rows[j]["SEQ_NO"].ToString();

                        //if (ds_R_HOEI_Carton.Tables[0].Rows[j]["Tori_CD"].ToString() == "FDTH LOT" | ds_R_HOEI_Carton.Tables[0].Rows[j]["Tori_CD"].ToString() == "FDTH N" | ds_R_HOEI_Carton.Tables[0].Rows[j]["Tori_CD"].ToString() == "FDTH O LOT" | ds_R_HOEI_Carton.Tables[0].Rows[j]["Tori_CD"].ToString() == "FDTH O N" | ds_R_HOEI_Carton.Tables[0].Rows[j]["Tori_CD"].ToString() == "EIC LOT" | ds_R_HOEI_Carton.Tables[0].Rows[j]["Tori_CD"].ToString() == "EIC N")
                        //{
                        str_Binary = ds_R_HOEI_Carton.Tables[0].Rows[j]["FB_NO"].ToString() + @"/" + ds_R_HOEI_Carton.Tables[0].Rows[j]["FBPOS_NO"].ToString() + @"/" + ds_R_HOEI_Carton.Tables[0].Rows[j]["SEQ_NO"].ToString();

                        BCCODE.Encode(BarcodeLib.TYPE.CODE128, str_Binary);
                        image = BCCODE.EncodedImage;
                        image.Save(Application.StartupPath + @"\TempFB.bmp", ImageFormat.Bmp);
                        dr_lb.BarCode1 = File.ReadAllBytes(Application.StartupPath + @"\TempFB.bmp");
                        //}
                        //else
                        //{
                        //    dr_lb.BarCode1 = System.Text.Encoding.Unicode.GetBytes("");
                        //}

                        dr_lb.Page = ds_R_HOEI_Carton.Tables[0].Rows[j]["PAGE_SHOW"].ToString();
                        //dt_Report.AcceptChanges();
                        dt_Report.Rows.Add(dr_lb);
                        
                        //string str_Data = ds_R_HOEI_Carton.Tables[0].Rows[j]["Print_Content"].ToString();
                        //string[] lstr_Values = str_Data.Split(new string[] { "<#&>" }, StringSplitOptions.RemoveEmptyEntries);
                        //dt_Report.Rows.Clear();
                        //foreach (string str_SubValue in lstr_Values)
                        //{
                        //    if (!str_SubValue.Contains("<#$>"))
                        //    {
                        //        continue;
                        //    }

                        //    G_Print_HOEI_Carton(str_SubValue.Substring(str_SubValue.IndexOf("<#$>") + 4));
                            
                        //}
                        int_Paper = int_Paper + 1;
                    }
                    if (int_Paper >= 0)
                    {
                        
                        return true;
                        //imageObject = (BlobFieldObject)rpt.ReportDefinition.ReportObjects["BarCode11"] as BlobFieldObject;
                        //imageObject.Width = 91 * 15; //报表中的长宽单位是缇，1像素=15缇
                        //imageObject.Height = 91 * 15;
                    }
                    else
                        return false;
                    break;
            }
            if (connect_CS != null)
            {
                if (!G_CommonClassDB.G_DB_Dispose(connect_CS))
                {
                    //P_MessageBox_Disconnection();
                }
            }
            return false;
        }
        public static void G_PrintBonded(string str_Value)
        {
            string[] Info = str_Value.Split(new string[] { "<#$>" }, StringSplitOptions.None);
            ds_Label.DataRow dr_lb = dt_Report.NewDataRow();

            dr_lb.Invoice = Info[0].ToString();
            dr_lb.CaseNo = Info[1].ToString();
            dr_lb.Unso_CD = Info[2].ToString();
            dr_lb.Jyht_No = Info[3].ToString();
            dr_lb.Ship_No = Info[4].ToString();
            //dr_lb.Shoh_CD=
            //dr_lb.IssuingDate = Info[2].ToString();
            QRCodeEncoder bcQRCode = new QRCodeEncoder();

            Image image = bcQRCode.Encode("ShipNo" + Info[4].ToString());
            string str_ImageFile = Application.StartupPath + @"\Temp.bmp";
            FileStream fs = new FileStream(str_ImageFile, FileMode.OpenOrCreate, FileAccess.Write);
            image.Save(fs, ImageFormat.Bmp);
            fs.Close();
            dr_lb.BarCode = File.ReadAllBytes(Application.StartupPath + @"\Temp.bmp");

            dt_Report.Rows.Add(dr_lb);
        }

        public bool G_PrintShipCase(string strQue_ID)
        {
            if (dt_Report != null)
            {
                dt_Report.Clear();
            }
            SqlConnection connect_CS = null;
            SqlCommand sqlCmd_CS = null;
            if (!G_CommonClassDB.G_DB_Connect(out connect_CS))
            {
                MessageBox.Show(Resources.P_Search, Resources.DB接続エラー);
                return false;
            }
            DataSet ds_R_ShipCase = new DataSet();

            sqlCmd_CS = connect_CS.CreateCommand();
            SqlParameter[] sqlPara_CS = new SqlParameter[1];
            sqlPara_CS[0] = G_CommonClassDB.G_DB_SetSQLDBParameter("@PrintQue_No", ParameterDirection.Input, SqlDbType.Int, 1, strQue_ID);

            switch (G_CommonClassDB.G_DB_ExecStoredProc(connect_CS, sqlCmd_CS, "USP_PC_F_R_ShipCase_DataSelect", sqlPara_CS, out ds_R_ShipCase))
            {
                case G_CommonDefine.RetValue.FoldarNotExistsError:
                    break;
                case G_CommonDefine.RetValue.FileNotExistsError:
                    break;
                case G_CommonDefine.RetValue.UndefinedError:
                    break;
                case G_CommonDefine.RetValue.NoData:
                    break;
                case G_CommonDefine.RetValue.GetData:
                    int int_Paper = -1;
                    for (int j = 0; j < ds_R_ShipCase.Tables[0].Rows.Count; j++)
                    {
                        string str_Data = ds_R_ShipCase.Tables[0].Rows[j]["Invoice_No"].ToString() + "<#$>" +
                            ds_R_ShipCase.Tables[0].Rows[j]["Case_No"].ToString() + "<#$>" +
                            ds_R_ShipCase.Tables[0].Rows[j]["UnSo_No"].ToString() + "<#$>" +
                            ds_R_ShipCase.Tables[0].Rows[j]["Jyht_No"].ToString() + "<#$>" +
                            ds_R_ShipCase.Tables[0].Rows[j]["Ship_No"].ToString() + "<#$>";
                        G_PrintBonded(str_Data);
                        int_Paper = int_Paper + 1;
                    }
                    if (int_Paper >= 0)
                    {
                        return true;
                        //imageObject = (BlobFieldObject)rpt.ReportDefinition.ReportObjects["BarCode11"] as BlobFieldObject;
                        //imageObject.Width = 91 * 15; //报表中的长宽单位是缇，1像素=15缇
                        //imageObject.Height = 91 * 15;
                    }
                    else
                        return false;
                    break;
            }
            if (connect_CS != null)
            {
                if (!G_CommonClassDB.G_DB_Dispose(connect_CS))
                {
                    //P_MessageBox_Disconnection();
                }
            }
            return false;
        }

        public static void G_Print_HOEI_Carton(string str_Value)
        {
            DotNetBarcode bc = new DotNetBarcode(DotNetBarcode.Types.QRCode);
            string str_Binary = "";
            DateTime dt_Date = DateTime.Now;
            string str_Date = "";
            string[] Info = str_Value.Split(new string[] { "<#$>" }, StringSplitOptions.None);
            //ds_Label.DataDataTable dt_Report = new ds_Label.DataDataTable();
            if (DateTime.TryParse(Info[4], out dt_Date))
            {
                str_Date = dt_Date.Year.ToString("D4") + dt_Date.Month.ToString("D2") + dt_Date.Day.ToString("D2");
            }

            ds_Label.DataRow dr_lb = dt_Report.NewDataRow();
            dr_lb.Tori_CD = Info[0];
            dr_lb.Shoh_CD = Info[1];

            dr_lb.Jyot_KB = Info[14];
            dr_lb.Ref = Info[8];
            dr_lb.NOUK_DT = Info[4];
            dr_lb.Work_CD = Info[5];
            dt_Report.Rows.Add(dr_lb);
            dr_lb.Lot_No = Info[8];
            dr_lb.Qty = Info[6];
            dr_lb.CaseNo = "Location" + Info[12];
            if (Info.Length > 15)
            {
                dr_lb.IssuingDate = "重";
            }

            str_Binary = "N" + SetLenth(Info[9], 20) + SetLenth(Info[10], 5) + SetLenth(Convert.ToInt32(Info[11]).ToString(), 5) + SetLenth(Info[0], 15) + SetLenth(Info[1], 80) + SetLenth(Info[8], 50) + SetLenth(Info[2], 2) + SetLenth(Info[6], 5) + SetLenth(str_Date, 8);
            bc.Save(str_Binary, Application.StartupPath + @"\Temp.bmp", 200, 200);
            dr_lb.BarCode = File.ReadAllBytes(Application.StartupPath + @"\Temp.bmp");
            dr_lb.Invoice = Info[9] + @"/" + Info[10] + @"/" + Convert.ToInt32(Info[11]).ToString();

            dr_lb.Page = Convert.ToInt32(Info[11]).ToString() + "/" + Info[13];
            dt_Report.AcceptChanges();
            

            for (int int_i = Convert.ToInt32(Info[11]); int_i < Convert.ToInt32(Info[11]) + Convert.ToInt32(Info[7]); int_i++)
            {
                
                //cy_NOSerial cy = new cy_NOSerial();
                //cy.SetDataSource((DataTable)dt_Report);
                //cy.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)int_Paper;
                //cy.PrintOptions.PrinterName = str_Printer;
                ////cy.ExportToDisk(ExportFormatType.PortableDocFormat, DateTime.Now.Second.ToString() + "Buff.pdf");                
                //cy.PrintToPrinter(1, true, 1, 1);
                //cy.Dispose();
            }
            
        }
        public static string SetLenth(string s, int len)
        {
            return s.Length > len ? s.Remove(len) : s.PadRight(len, ' ');
        }

        private static void P_BindGrid(SheetView sheet, DataTable dtPrintQue)
        {
            if ((dtPrintQue == null) || (dtPrintQue.Rows.Count == 0))
            {
                sheet.RowCount = 0;
                //this.lbTotal.Text = "0";
                return;
            }
            sheet.RowCount = dtPrintQue.Rows.Count;

            for (int i = 0; i < dtPrintQue.Rows.Count; i++)
            {
                DataRow Row = dtPrintQue.Rows[i];



                sheet.Cells[i, 0].Tag = i + 1;
                sheet.Cells[i, 0].VerticalAlignment = CellVerticalAlignment.Center;
                sheet.Cells[i, 0].HorizontalAlignment = CellHorizontalAlignment.Center;
                sheet.Cells[i, 1].Value = Row["Que_ID"];
                sheet.Cells[i, 2].Value = Row["Print_NM"];
                sheet.Cells[i, 3].Value = Row["Printer_NM"];
                sheet.Cells[i, 4].Value = Row["Work_CD"];
                sheet.Cells[i, 5].Value = Row["Work_NM"];
                sheet.Cells[i, 6].Value = Row["Reg_DT"];
                sheet.Cells[i, 7].Value = Row["Fin_FG_NM"];
            }
        }

        private static DataSet G_PrintSerialList(string str_FB_NO, string str_FBPOS_NO, string str_SEQ_NO, string str_Work_CD)
        {
            DataSet ds = new DataSet();
            try
            {
                DotNetBarcode bc = new DotNetBarcode(DotNetBarcode.Types.QRCode);
                ds_Label.DataDataTable dt_Report = new ds_Label.DataDataTable();
                //string[] Info = str_Value.Split(new string[] { "<#$>" }, StringSplitOptions.None);
                DataTable dt_Data = G_CommonClassBussniss.G_A4SerialPrint_GetHeaderData(str_FB_NO, str_FBPOS_NO, str_SEQ_NO);
                DataTable dt_SerialList = G_CommonClassBussniss.G_A4SerialPrint_GetDetailData(str_FB_NO, str_FBPOS_NO, str_SEQ_NO);

        
                //ds_Data.USP_HHT_ReportSerial_DataSearchDataTable dt_Data = taData.GetData(Convert.ToInt32(Info[2]), Convert.ToInt32(Info[3]), Convert.ToInt32(Info[4]));
                //ds_Data.USP_HHT_ReportSerial_DataSearchRow dr_Data = (ds_Data.USP_HHT_ReportSerial_DataSearchRow)dt_Data.Rows[0];
                //ds_Data.USP_COM_T_Serial_DataSelectDataTable dt_SerialList = taList.GetData(Convert.ToInt32(Info[2]), Convert.ToInt32(Info[3]), Convert.ToInt32(Info[4]));

                DataRow dr_Data = dt_Data.Rows[0];

                ds_Label.ListDataTable dt_List = new ds_Label.ListDataTable();
                ds_Label.ListRow dr_List;
                //DataTable dt_List = new DataTable();
                //DataRow dr_List;

                ds_Label.DataRow dr_lb = dt_Report.NewDataRow();
               

                if (dt_Data.Rows.Count != 1)
                {
                    ds = null;
                    return ds;
                }
                //   P_AddParameter("NOUK_DT", dr_Data.Nouk_DT.ToShortDateString());
                DateTime Nyuk_DT;
                if (DateTime.TryParse(dr_Data["Nyuk_DT"].ToString(), out Nyuk_DT))
                {
                    dr_lb.NOUK_DT = Nyuk_DT.ToShortDateString();
                }
                else
                {
                    dr_lb.NOUK_DT = "";
                }
                dr_lb.Jyot_KB = dr_Data["Jyot_NM"].ToString();
                dr_lb.Lot_No = dr_Data["Lot_CD"].ToString();
                //dr_lb.NOUK_DT = dr_Data.Nyuk_DT == null ? "" : dr_Data.Nyuk_DT.ToShortDateString();
                dr_lb.Page = dr_Data["SEQ_NO"].ToString() + @"/" + dr_Data["MaxSeq"].ToString();
                dr_lb.Qty = dr_Data["Yote_QT"].ToString();
                dr_lb.Ref = dr_Data["Lot_CD"].ToString();

                dr_lb.Shoh_CD = dr_Data["Shoh_CD"].ToString();
                dr_lb.Tori_CD = dr_Data["Tori_CD"].ToString();
                dr_lb.Work_CD = str_Work_CD;
                dr_lb.Invoice = dr_Data["FB_NO"].ToString() + @"/" + dr_Data["FBPOS_NO"].ToString() + @"/" + dr_Data["SEQ_NO"].ToString();
                dt_Report.Rows.Add(dr_lb);
                if ((dt_SerialList != null) && (dt_SerialList.Rows.Count > 0))
                {
                    for (int int_i = 0; int_i < dt_SerialList.Rows.Count; int_i = int_i + 3)
                    {
                        dr_List = dt_List.NewListRow();
                        for (int int_j = 0; int_j < 3; int_j++)
                        {
                            dr_List["Serial" + Convert.ToString(int_j + 1)] = dt_SerialList.Rows[int_i + int_j]["Serial_No"];
                            bc.Save(SetLenth(dr_Data["Shoh_CD"].ToString(), 80) + "" + SetLenth(dt_SerialList.Rows[int_i + int_j]["Serial_No"].ToString(), 18), Application.StartupPath + @"\Temp_SerialList.bmp", 200, 200);
                            dr_List["BarCode" + Convert.ToString(int_j + 1)] = File.ReadAllBytes(Application.StartupPath + @"\Temp_SerialList.bmp");
                            if (int_i + int_j + 1 >= dt_SerialList.Rows.Count)
                            {
                                for (; int_j + 1 < 3; int_j++)
                                {
                                    //dr_List["BarCode" + Convert.ToString(int_j + 2)] = File.ReadAllBytes(Application.StartupPath + @"\Temp.bmp");
                                }
                                break;
                            }
                        }
                        dt_List.Rows.Add(dr_List);
                    }
                }
                
                ds.Tables.Add(dt_List);
                ds.Tables.Add(dt_Report);


                //cy_SerialList cy = new cy_SerialList();


                //cy.SetDataSource(ds);
                ////cy.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)int_Paper;
                //cy.PrintOptions.PrinterName = str_Printer;
                ////cy.ExportToDisk(ExportFormatType.PortableDocFormat, DateTime.Now.Second.ToString() + "Buff.pdf");
                //cy.PrintToPrinter(1, true, 1, 99);
                //cy.Dispose();
                return ds;
            }
            catch (Exception err)
            {

                MessageBox.Show(err.Message);
                return ds;
            }
        }

        private static DataTable G_PrintSerialSingle(string str_Shoh_CD, string str_SerialNo)
        {
            DotNetBarcode bc = new DotNetBarcode(DotNetBarcode.Types.QRCode);
            ds_Label.DataDataTable dt_Report = new ds_Label.DataDataTable();
            //string[] Info = str_Value.Split(new string[] { "<#$>" }, StringSplitOptions.None);




            ds_Label.DataRow dr_lb = dt_Report.NewDataRow();

            dr_lb.Invoice = str_SerialNo;
            dr_lb.Shoh_CD = str_Shoh_CD;

            //bc.Save(SetLenth(str_Shoh_CD, 80) + " " + SetLenth(str_SerialNo, 19), Application.StartupPath + @"\Temp_Single.bmp", 120, 120);
            bc.Save(SetLenth(str_Shoh_CD, 80) + "" + SetLenth(str_SerialNo, 18), Application.StartupPath + @"\Temp_Single.bmp", 200, 200);
            dr_lb.BarCode = File.ReadAllBytes(Application.StartupPath + @"\Temp_Single.bmp");

            dt_Report.Rows.Clear();
            dt_Report.Rows.Add(dr_lb);

            return dt_Report;
            //cy_SigleSerial cy = new cy_SigleSerial();
            //cy.SetDataSource((DataTable)dt_Report);
            //cy.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)int_Paper;
            //cy.PrintOptions.PrinterName = str_Printer;
            ////cy.ExportToDisk(ExportFormatType.PortableDocFormat, DateTime.Now.Second.ToString() + "Buff.pdf");

            //cy.PrintToPrinter(1, true, 1, 1);
            //cy.Dispose();
        }

        private static DataTable G_PrintSerialMultiple(DataTable dtSerial)
        {
            DotNetBarcode bc = new DotNetBarcode(DotNetBarcode.Types.QRCode);
            ds_Label.DataDataTable dt_Report = new ds_Label.DataDataTable();
            //string[] Info = str_Value.Split(new string[] { "<#$>" }, StringSplitOptions.None);
            string str_SerialNo = string.Empty;
            string str_Shoh_CD = string.Empty;
            dt_Report.Clear();
            foreach (DataRow Row in dtSerial.Rows)
            {
                ds_Label.DataRow dr_lb = dt_Report.NewDataRow();

                str_SerialNo = Row["Serial_No"].ToString();
                str_Shoh_CD = Row["Shoh_CD_Tori"].ToString();

                dr_lb.Invoice = str_SerialNo;
                dr_lb.Shoh_CD = str_Shoh_CD;

                //bc.Save(SetLenth(str_Shoh_CD, 80) + " " + SetLenth(str_SerialNo, 19), Application.StartupPath + @"\Temp_Multiple.bmp", 120, 120);
                bc.Save(SetLenth(str_Shoh_CD, 80) + "" + SetLenth(str_SerialNo, 18), Application.StartupPath + @"\Temp_Multiple.bmp", 200, 200);
                dr_lb.BarCode = File.ReadAllBytes(Application.StartupPath + @"\Temp_Multiple.bmp");
                dt_Report.Rows.Add(dr_lb);
            }
            return dt_Report;
        }

        private bool G_HOEI_Carton_SH(string strQue_ID)
        {
            DotNetBarcode bc = new DotNetBarcode(DotNetBarcode.Types.QRCode);
            string str_Binary = "";
            DateTime dt_Date = DateTime.Now;
            string str_Date = "";
            SqlConnection connect_CS = null;
            SqlCommand sqlCmd_CS = null;
            if (!G_CommonClassDB.G_DB_Connect(out connect_CS))
            {
                MessageBox.Show(Resources.P_Search, Resources.DB接続エラー);
                return false;
            }
            DataSet ds_R_HOEI_Carton = new DataSet();

            sqlCmd_CS = connect_CS.CreateCommand();
            SqlParameter[] sqlPara_CS = new SqlParameter[1];
            sqlPara_CS[0] = G_CommonClassDB.G_DB_SetSQLDBParameter("@PrintQue_No", ParameterDirection.Input, SqlDbType.Int, 1, strQue_ID);

            switch (G_CommonClassDB.G_DB_ExecStoredProc(connect_CS, sqlCmd_CS, "USP_PC_F_R_HOEI_Carton_DataSelect", sqlPara_CS, out ds_R_HOEI_Carton))
            {
                case G_CommonDefine.RetValue.FoldarNotExistsError:
                    break;
                case G_CommonDefine.RetValue.FileNotExistsError:
                    break;
                case G_CommonDefine.RetValue.UndefinedError:
                    break;
                case G_CommonDefine.RetValue.NoData:
                    break;
                case G_CommonDefine.RetValue.GetData:
                    int int_Paper = -1;
                    dt_Report = new ds_Label.DataDataTable();
                    for (int j = 0; j < ds_R_HOEI_Carton.Tables[0].Rows.Count; j++)
                    {
                        //string str_Data = ds_R_HOEI_Carton.Tables[0].Rows[j]["Troi_CD"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["Shoh_CD"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["Condition"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["REF"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["Date"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["Work_CD"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["Qty"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["Label"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["Lot_No"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["FB_NO"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["FBPOS_NO"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["int_StartSeq"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["Location"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["MaxSeq"].ToString() + "<#$>" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["StrCondition"].ToString() + "<#$>";

                        if (DateTime.TryParse(ds_R_HOEI_Carton.Tables[0].Rows[j]["NYUK_DT"].ToString(), out dt_Date))
                        {
                            str_Date = dt_Date.Year.ToString("D4") + dt_Date.Month.ToString("D2") + dt_Date.Day.ToString("D2");
                        }

                        ds_Label.DataRow dr_lb = dt_Report.NewDataRow();
                        dr_lb.Tori_CD = ds_R_HOEI_Carton.Tables[0].Rows[j]["Tori_CD"].ToString();
                        //dr_lb.Shoh_CD = ds_R_HOEI_Carton.Tables[0].Rows[j]["Shoh_CD"].ToString() + "\r\n" +
                        //    ds_R_HOEI_Carton.Tables[0].Rows[j]["Shoh_NM"].ToString();
                        dr_lb.Shoh_CD = ds_R_HOEI_Carton.Tables[0].Rows[j]["Shoh_CD"].ToString();
                        
                        //dr_lb.Souk_NM = ds_R_HOEI_Carton.Tables[0].Rows[j]["SOUK_CD"].ToString();

                        dr_lb.Jyot_KB = ds_R_HOEI_Carton.Tables[0].Rows[j]["JYOT_NM"].ToString();
                        dr_lb.Ref = ds_R_HOEI_Carton.Tables[0].Rows[j]["Lot_CD"].ToString();
                        dr_lb.NOUK_DT = ds_R_HOEI_Carton.Tables[0].Rows[j]["NYUK_DT"].ToString();
                        dr_lb.Work_CD = ds_R_HOEI_Carton.Tables[0].Rows[j]["WORK_CD"].ToString();

                        //dr_lb.Lot_No = ds_R_HOEI_Carton.Tables[0].Rows[j]["SUPPLIER_NM"].ToString();
                        dr_lb.Lot_No = ds_R_HOEI_Carton.Tables[0].Rows[j]["Lot_CD"].ToString();
                        dr_lb.Qty = ds_R_HOEI_Carton.Tables[0].Rows[j]["ALL_QT"].ToString();
                        dr_lb.CaseNo = "Location" + ds_R_HOEI_Carton.Tables[0].Rows[j]["B_Loca_CD"].ToString();
                        //reprint
                        dr_lb.IssuingDate = ds_R_HOEI_Carton.Tables[0].Rows[j]["RePrint_Mark"].ToString();
                        //if (Info.Length > 15)
                        //{
                        //    dr_lb.IssuingDate = "重";
                        //}

                        str_Binary = "N" + SetLenth(ds_R_HOEI_Carton.Tables[0].Rows[j]["FB_NO"].ToString(), 20) +
                            SetLenth(ds_R_HOEI_Carton.Tables[0].Rows[j]["FBPOS_NO"].ToString(), 5) +
                            SetLenth(ds_R_HOEI_Carton.Tables[0].Rows[j]["SEQ_NO"].ToString(), 5) +
                            SetLenth(ds_R_HOEI_Carton.Tables[0].Rows[j]["Tori_CD"].ToString(), 15) +
                            SetLenth(ds_R_HOEI_Carton.Tables[0].Rows[j]["Shoh_CD"].ToString(), 80) +
                            SetLenth(ds_R_HOEI_Carton.Tables[0].Rows[j]["Lot_CD"].ToString(), 50) +
                            SetLenth("10", 2) +
                            SetLenth(ds_R_HOEI_Carton.Tables[0].Rows[j]["ALL_QT"].ToString(), 5) +
                            SetLenth(str_Date, 8);
                        bc.Save(str_Binary, Application.StartupPath + @"\Temp_CatronSH.bmp", 400, 400);
                        dr_lb.BarCode = File.ReadAllBytes(Application.StartupPath + @"\Temp_CatronSH.bmp");
                        dr_lb.Invoice = ds_R_HOEI_Carton.Tables[0].Rows[j]["FB_NO"].ToString() + @"/" +
                            ds_R_HOEI_Carton.Tables[0].Rows[j]["FBPOS_NO"].ToString() + @"/" +
                            ds_R_HOEI_Carton.Tables[0].Rows[j]["SEQ_NO"].ToString();

                        dr_lb.Page = ds_R_HOEI_Carton.Tables[0].Rows[j]["PAGE_SHOW"].ToString();
                        //dt_Report.AcceptChanges();
                        dt_Report.Rows.Add(dr_lb);

                        //string str_Data = ds_R_HOEI_Carton.Tables[0].Rows[j]["Print_Content"].ToString();
                        //string[] lstr_Values = str_Data.Split(new string[] { "<#&>" }, StringSplitOptions.RemoveEmptyEntries);
                        //dt_Report.Rows.Clear();
                        //foreach (string str_SubValue in lstr_Values)
                        //{
                        //    if (!str_SubValue.Contains("<#$>"))
                        //    {
                        //        continue;
                        //    }

                        //    G_Print_HOEI_Carton(str_SubValue.Substring(str_SubValue.IndexOf("<#$>") + 4));

                        //}
                        int_Paper = int_Paper + 1;
                    }
                    if (int_Paper >= 0)
                    {

                        return true;
                        //imageObject = (BlobFieldObject)rpt.ReportDefinition.ReportObjects["BarCode11"] as BlobFieldObject;
                        //imageObject.Width = 91 * 15; //报表中的长宽单位是缇，1像素=15缇
                        //imageObject.Height = 91 * 15;
                    }
                    else
                        return false;
                    break;
            }
            if (connect_CS != null)
            {
                if (!G_CommonClassDB.G_DB_Dispose(connect_CS))
                {
                    //P_MessageBox_Disconnection();
                }
            }
            return false;
        }

        private ds_LotLabel G_PrintLotLabel(DataTable dt_Data)
        {
            //DotNetBarcode bc = new DotNetBarcode(DotNetBarcode.Types.Code39);
            DotNetBarcode bcQR = new DotNetBarcode(DotNetBarcode.Types.QRCode);
            ds_LotLabel ds_LotLabel = new ds_LotLabel();
            string str_Binary = "";

            Image image = new Bitmap(300, 30);
            Barcode bc = new Barcode();
            bc.EncodedType = TYPE.CODE39;
            string filename = Application.StartupPath + @"\Temp_LotLabel.png";

            foreach (DataRow Row in dt_Data.Rows)
            {
                DataRow dr_Label = ds_LotLabel.Tables[0].NewRow();

                dr_Label["Tori_CD"] = Row["Tori_CD"];
                dr_Label["Shoh_CD"] = Row["Shoh_NM"];
                dr_Label["Lot_CD"] = Row["Lot_CD"];
                dr_Label["Hinmei_NN"] = Row["Supplier_NM"];
                dr_Label["ALL_QT"] = Row["ALL_QT"];
                dr_Label["Work_CD"] = Row["Work_CD"];
                dr_Label["Hinmei_NN_LB"] = "(3N)1" + Row["Supplier_NM"].ToString() + " " + Row["ALL_QT"].ToString();

                str_Binary = "3N1" + Row["Supplier_NM"].ToString() + " " + Row["ALL_QT"].ToString();
               
                //bc.Encode(TYPE.CODE39, 300, 30);
                //bc.RawData = str_Binary;
                //bc.SaveImage(filename, SaveTypes.PNG);
                bcQR.Save(str_Binary, filename, 200, 200);
                dr_Label["Hinmei_NM_BC"] = File.ReadAllBytes(filename);

                //一维条码 PLOT 条码
                bc.RawData = str_Binary;
                bc.Encode(TYPE.CODE128, 100, 30);
                bc.SaveImage(filename, SaveTypes.PNG);
                dr_Label["Barcode1"] = File.ReadAllBytes(filename);


                dr_Label["Lot_CD_LB"] = "(3N)2" + " " + Row["Lot_CD"].ToString() + " " + "107250";
                str_Binary = "3N2" + " " + Row["Lot_CD"].ToString() + " " + "";
                bc.RawData = str_Binary;
                bc.Encode(TYPE.CODE39, 300, 30);
                bc.SaveImage(filename, SaveTypes.PNG);
                dr_Label["Lot_CD_BC"] = File.ReadAllBytes(filename);

                dr_Label["Reg_DT"] = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss", DateTimeFormatInfo.InvariantInfo);

                ds_LotLabel.Tables[0].Rows.Add(dr_Label);
            }
            ds_LotLabel.AcceptChanges();
            return ds_LotLabel;
           
        }


        private ds_LotLabel G_PrintLotLabelList(DataTable dt_Data)
        {
            //DotNetBarcode bc = new DotNetBarcode(DotNetBarcode.Types.Code39);
            DotNetBarcode bcQR = new DotNetBarcode(DotNetBarcode.Types.QRCode);

            ds_LotLabel ds_LotLabel = new ds_LotLabel();
            string str_Binary = "";

            Image image = new Bitmap(300, 30);
            Barcode bc = new Barcode();
            bc.EncodedType = TYPE.CODE39;
            string filename = Application.StartupPath + @"\Temp_LotLabel.png";
            DateTime Reg_DT;

            foreach (DataRow Row in dt_Data.Rows)
            {
                DataRow dr_Label = ds_LotLabel.Tables[0].NewRow();

                dr_Label["Tori_CD"] = Row["Tori_CD"];
                dr_Label["Shoh_CD"] = Row["Shoh_NM"];
                dr_Label["Lot_CD"] = Row["Lot_CD"];
                dr_Label["Hinmei_NN"] = Row["Hinmei_NN"];
                dr_Label["ALL_QT"] = Row["ALL_QT"];
                dr_Label["Work_CD"] = Row["Work_CD"];
                dr_Label["Hinmei_NN_LB"] = Row["Hinmei_NN_LB"].ToString();

                str_Binary = Row["Hinmei_NM_BC"].ToString();
                //bc.RawData = str_Binary;
                //bc.Encode(TYPE.CODE39, 300, 30);
                //bc.SaveImage(filename, SaveTypes.PNG);
                //Modify by Michael Date 2010-03-08
                bcQR.Save(str_Binary, filename, 200, 200);
                dr_Label["Hinmei_NM_BC"] = File.ReadAllBytes(filename);

                //一维条码 PLOT 条码
                bc.RawData = str_Binary;
                bc.Encode(TYPE.CODE128, 100, 30);
                bc.SaveImage(filename, SaveTypes.PNG);
                dr_Label["Barcode1"] = File.ReadAllBytes(filename);

                dr_Label["Lot_CD_LB"] = Row["Lot_CD_LB"].ToString();
                str_Binary = Row["Lot_CD_BC"].ToString();
                bc.RawData = str_Binary;
                bc.Encode(TYPE.CODE39, 300, 30);
                bc.SaveImage(filename, SaveTypes.PNG);
                dr_Label["Lot_CD_BC"] = File.ReadAllBytes(filename);

                bool bl_Reg_DT = DateTime.TryParse(Row["Reg_DT"].ToString(), out Reg_DT);

                dr_Label["Reg_DT"] = Reg_DT.ToString("yyyy/MM/dd HH:mm:ss", DateTimeFormatInfo.InvariantInfo);

                ds_LotLabel.Tables[0].Rows.Add(dr_Label);
            }
            ds_LotLabel.AcceptChanges();
            return ds_LotLabel;

        }

        private DataTable P_NewLotLabelDataSearch(string strQue_ID)
        {
            DataTable dt = null;
            DotNetBarcode bc = new DotNetBarcode(DotNetBarcode.Types.QRCode);
           
            SqlConnection connect_CS = null;
            SqlCommand sqlCmd_CS = null;
            if (!G_CommonClassDB.G_DB_Connect(out connect_CS))
            {
                MessageBox.Show(Resources.P_Search, Resources.DB接続エラー);
                return dt;
            }
            DataSet ds_R_HOEI_Carton = new DataSet();

            sqlCmd_CS = connect_CS.CreateCommand();
            SqlParameter[] sqlPara_CS = new SqlParameter[1];
            sqlPara_CS[0] = G_CommonClassDB.G_DB_SetSQLDBParameter("@PrintQue_No", ParameterDirection.Input, SqlDbType.Int, 1, strQue_ID);

            switch (G_CommonClassDB.G_DB_ExecStoredProc(connect_CS, sqlCmd_CS, "USP_PC_F_R_HOEI_Carton_DataSelect", sqlPara_CS, out ds_R_HOEI_Carton))
            {
                case G_CommonDefine.RetValue.FoldarNotExistsError:
                    break;
                case G_CommonDefine.RetValue.FileNotExistsError:
                    break;
                case G_CommonDefine.RetValue.UndefinedError:
                    break;
                case G_CommonDefine.RetValue.NoData:
                    break;
                case G_CommonDefine.RetValue.GetData:

                    dt = ds_R_HOEI_Carton.Tables[0];
                    break;
            }
            if (connect_CS != null)
            {
                if (!G_CommonClassDB.G_DB_Dispose(connect_CS))
                {
                    //P_MessageBox_Disconnection();
                }
            }
            return dt;
        }

        //public static void G_PrintNoSerial(string str_Value, string str_Printer, int int_Paper)
        //{
        //    DotNetBarcode bc = new DotNetBarcode(DotNetBarcode.Types.QRCode);
        //    string str_Binary = "";
        //    DateTime dt_Date = DateTime.Now;
        //    string str_Date = "";
        //    string[] Info = str_Value.Split(new string[] { "<#$>" }, StringSplitOptions.None);
        //    ds_Label.DataDataTable dt_Report = new ds_Label.DataDataTable();
        //    if (DateTime.TryParse(Info[4], out dt_Date))
        //    {
        //        str_Date = dt_Date.Year.ToString("D4") + dt_Date.Month.ToString("D2") + dt_Date.Day.ToString("D2");
        //    }

        //    ds_Label.DataRow dr_lb = dt_Report.NewDataRow();
        //    dr_lb.Tori_CD = Info[0];
        //    dr_lb.Shoh_CD = Info[1];

        //    dr_lb.Jyot_KB = Info[14];
        //    dr_lb.Ref = Info[3];
        //    dr_lb.NOUK_DT = Info[4];
        //    dr_lb.Work_CD = Info[5];
        //    dt_Report.Rows.Add(dr_lb);
        //    dr_lb.Lot_No = Info[8];
        //    dr_lb.Qty = Info[6];
        //    dr_lb.CaseNo = "Location" + Info[12];
        //    if (Info.Length > 15)
        //    {
        //        dr_lb.IssuingDate = "重";
        //    }

        //    for (int int_i = Convert.ToInt32(Info[11]); int_i < Convert.ToInt32(Info[11]) + Convert.ToInt32(Info[7]); int_i++)
        //    {
        //        str_Binary = "N" + SetLenth(Info[9], 20) + SetLenth(Info[10], 5) + SetLenth(int_i.ToString(), 5) + SetLenth(Info[0], 15) + SetLenth(Info[1], 80) + SetLenth(Info[8], 50) + SetLenth(Info[2], 2) + SetLenth(Info[6], 5) + SetLenth(str_Date, 8);
        //        bc.Save(str_Binary, str_TempFileName, 200, 200);
        //        dr_lb.BarCode = File.ReadAllBytes(Application.StartupPath + @"\Temp.bmp");
        //        dr_lb.Invoice = Info[9] + @"/" + Info[10] + @"/" + int_i.ToString();

        //        cy_NOSerial cy = new cy_NOSerial();
        //        dr_lb.Page = int_i.ToString() + "/" + Info[13];

        //        cy.SetDataSource((DataTable)dt_Report);
        //        cy.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)int_Paper;
        //        cy.PrintOptions.PrinterName = str_Printer;
        //        //cy.ExportToDisk(ExportFormatType.PortableDocFormat, DateTime.Now.Second.ToString() + "Buff.pdf");                
        //        cy.PrintToPrinter(1, true, 1, 1);
        //        cy.Dispose();
        //    }
        //}
    }
}